home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / comm / www / IBrowseScripts.lha / ibrowsescripts / rexx / newmail.ibrx < prev    next >
Text File  |  1999-03-04  |  8KB  |  286 lines

  1. /*
  2. Multi-part script for use with IBrowse and Yam (Miami).
  3.  
  4. Arguments:
  5.             ,reads newmail.
  6.     ALL        ,reads ALL mail.
  7.     ALTER    ,reads newmail and alters the status to old in yam.
  8.     CHECK    ,checks for mail using miami, disconnects.
  9.     SEND        , as CHECK but also sends your outgoing mail.
  10.     OTHER    ,reads any of yams folders 
  11.     DEBUG    ,if the IBrowsepart fails.. pinpoints mailfile.
  12.  */
  13. OPTIONS RESULTS
  14. OPTIONS FAILAT 21
  15. call addlib('libs:rexxreqtools.library',0,-30)
  16. NL=        '0a'x        /* newline */
  17. folder=0
  18. temppath='RAM:T/Newmail'
  19. title=    'Newmail by sorenf@hem1.passagen.se 1998'
  20. what_but=    '_IBrowse|_Yam|Cancel'
  21. tags=    'rt_pubscrname=IBROWSESCREEN'  /* Change here the name of the screen IBROWSE runs */
  22. where_txt='There is mail for You! Select viewer.'
  23. preset=0
  24.  
  25. ARG mode 
  26. IF mode='ALTER' THEN DO ; mode='' ; alt='YES' ; END
  27. IF POS('OTHER',mode)~=0 THEN DO 
  28.     len=LENGTH(mode)
  29.     IF len>5 THEN folder=DELSTR(mode,1,5)
  30.     mode='OTHER'
  31. END
  32.  
  33. IF ~SHOW('Ports','YAM') THEN CALL START "YAM","HIDE"
  34.  
  35. IF mode='CHECK' | mode='SEND' THEN DO
  36.     ADDRESS 'COMMAND' 'SETENV NOICQ'
  37.     ADDRESS 'YAM' 'mailcheck'; res=RESULT
  38.     IF res='0 0 0 0' THEN DO
  39.         IF ~SHOW('Ports','MIAMI.1') THEN CALL START "Miami","DONTCONNECT HIDE SETTINGS miami:miami.default"
  40.         IF SHOW('Ports','MIAMI.1') & SHOW('Ports','YAM')  THEN DO
  41.             ADDRESS 'MIAMI.1' 'ONLINE'
  42.             IF mode='SEND' THEN ADDRESS 'YAM' 'mailsendall'
  43.             good=RESULT
  44.             ADDRESS 'YAM' 'mailcheck'; res=result
  45.             ADDRESS 'MIAMI.1' 'OFFLINE'
  46.             ADDRESS 'COMMAND' 'WAIT 10'
  47.             ADDRESS 'MIAMI.1' 'QUIT'
  48.  
  49.         END
  50.     END
  51.     ADDRESS 'COMMAND' 'UNSETENV NOICQ'
  52.     IF res=-1 | good=-1 THEN SAY 'Somethingwentwrong'
  53.     IF res<1  THEN rtezrequest('Sorry ! No mail.',':(',title,'rtez_defaultresponse=1') 
  54.     EXIT
  55. END
  56.  
  57.  
  58.  
  59. IF mode='' THEN DO
  60.     sel=rtezrequest(where_txt,what_but,title,'rtez_defaultresponse=1') 
  61.     IF sel=0 then Exit
  62.     IF sel=2 then do; CALL SHOWYAM ; SETFOLDER 0; EXIT;    END
  63.     IF EXISTS('sys:c/play16') & EXISTS('Ibrowse:rexx/IBS_Images/mailsound.wav') THEN DO
  64.     ADDRESS 'COMMAND' 'Run >NIL: play16 >NIL: Ibrowse:rexx/IBS_Images/mailsound.wav'; END
  65. END
  66.  
  67. IF mode='OTHER' & folder=0 THEN DO
  68.     oldname='';list=''
  69.     ADDRESS 'YAM'
  70.     DO i=0 TO 12
  71.         'SETFOLDER' i
  72.         'GETFOLDERINFO' 'NAME'; name=RESULT
  73.  
  74.         IF name=oldname THEN BREAK
  75.     
  76.         say i||' '||NAME
  77.         oldname=name
  78.         list=list||i||' '||name||NL
  79.     END
  80.     long = rtgetlong(preset,list, "Enter a number:", , "rtgl_min = 0 rtgl_max = "i-1,'2')
  81.         if rtresult ~=0 then folder=long 
  82.         if rtresult =0 then EXIT
  83.         
  84.  
  85. END
  86.  
  87. /* ************** Here starts the IBrowse-display part ************ */
  88. IF ~SHOW('Ports','IBROWSE') THEN CALL START "IBROWSE",""
  89.  
  90. IF SHOW('Ports','IBROWSE') & SHOW('Ports','YAM') THEN DO
  91.  
  92.     NLNL=    '0a0a'x        /* 2 newlines  */
  93.     imgpath='="file://localhost/IBrowse:Rexx/IBS_Images/'
  94.     fileinc=    '<B><IMG SRC'||imgpath||'mailfile.png" ALT="File/s included!" > </B>'
  95.     repl=    '<B><IMG SRC'||imgpath||'mailrep.png" ALT="Replyed!" > </B>'
  96.     new=        '<B><IMG SRC'||imgpath||'mailnew.png" ALT="new" > </B>'
  97.     fresh=    '<B><IMG SRC'||imgpath||'mailfresh.png" ALT="fresh" > </B>'
  98.     repl=    '<B><IMG SRC'||imgpath||'mailrep.png" ALT="Replyed!" > </B>'
  99.     old=        '<B><IMG SRC'||imgpath||'mailread.png" ALT="Old!" > </B>'
  100.     more=    '<B><IMG SRC'||imgpath||'mailmore.png" ALT="More!" > </B>'
  101.     head=    '<HEAD><TITLE>NewMail by Sören Forsberg</TITLE></HEAD>'
  102.     mode_txt=    ' Here is your new mail.'
  103.     body=    '<BODY><BODY BGCOLOR="#F0F0F0"></BODY>'
  104.     pre=        '<PRE>'
  105.     epre=    '</PRE>'
  106.     ibserror= '</PRE><FONT COLOR=#FF0000>Newmail failed to decode this message correctly, please view with yam!</FONT><PRE>'
  107.     IF mode='ALL' THEN mode_txt=' Here is your mail.'
  108.     IF mode='DEBUG' THEN mode_txt=' DEBUGED'
  109.  
  110.     ADDRESS 'COMMAND' 'makedir >NIL: ' temppath 
  111.  
  112.     ADDRESS 'YAM'
  113.     'SetFolder' folder
  114.     GetFolderinfo MAX; max=RESULT
  115.     'GETFOLDERINFO' 'NAME'; name=RESULT
  116.     IF mode='OTHER' THEN mode_txt=name||':'
  117.     linkpage=head||'<BODY><BODY BGCOLOR="#F0F0F0"><BODY BACKGROUND'||imgpath||'mailback.png"></BODY><PRE><BIG>'||mode_txt||'</BIG>'||NL
  118.     DO a=0 TO max-1
  119.         setmail a
  120.         getmailinfo STA; status=result
  121.  
  122.         IF status='U' | status="N" | mode~='' THEN DO
  123.  
  124.             err=0
  125.             /* Get info from yam */
  126.             getmailinfo FRO ;            from=result
  127.             getmailinfo SUB ;            subject=LEFT(result,30)
  128.             getmailinfo FIL ;            file=result
  129.             IF mode='DEBUG' THEN say 'checking file: '||file
  130.  
  131.         /* use email as name if name is missing */
  132.             namepos=pos('<',from)
  133.             IF namepos=0 THEN Do 
  134.                 from=from||' <'||from ;namepos=pos('<',from)
  135.             END
  136.         /* split name and email-address */
  137.             name=LEFT(from,namepos-1) ;name=STRIP(name,'B','" ') ;name=LEFT(name,30)
  138.             email=DELSTR(from,1,namepos); email=STRIP(email,'T','>')
  139.             titel='From: '||name||'Subject: '||subject
  140.             mailto='<A HREF="mailto:'||email||'">'||email||'</A>'||NL
  141.  
  142.  
  143.         /* Read mailfile */
  144.             open(inputfile,file,'R')
  145.                 out=readch(inputfile,65000)
  146.             close(inputfile)
  147.  
  148.             bin=0
  149.             gem=0
  150.             html=0
  151.             list=''
  152.             content=0
  153.             boundary=''
  154.             post=pos(NLNL,out)
  155.             mailinfo=LEFT(out,post)
  156.             out=DELSTR(out,1,post)
  157.             bonpos=pos('boundary',mailinfo)
  158.  
  159.         /* set some stuff upp if multipart MIME */
  160.             IF bonpos~=0 THEN DO
  161.                 line=SUBSTR(mailinfo,bonpos,pos(NL,mailinfo,bonpos)-bonpos)
  162.                 boundary=SUBSTR(line,11,24)
  163.                 appex=bonpos
  164.                 oldposb=0
  165.                 DO FOREVER
  166.                     appex=pos(boundary,out,oldposb+1)
  167.                     IF appex~=0 THEN DO
  168.                         posb=pos(NLNL,out,appex)
  169.                         nextline=substr(out,appex,posb-appex)
  170.                         IF pos('text/plain',nextline)~=0 THEN DO
  171.                             gem=gem+1
  172.                             IF gem=1 THEN DO
  173.                                 CALL QUOTECUT
  174.                             END
  175.                         END
  176.                         IF pos('text/html',nextline)~=0 THEN DO
  177.                             html=html+1
  178.                             IF html=1 THEN DO
  179.                                 content=0
  180.                                 CALL QUOTECUT
  181.                             END
  182.                         END
  183.                         IF pos('application/octet-stream',nextline)~=0 THEN bin=bin+1
  184.                     END
  185.                     oldposb=posb
  186.                     IF appex=0   THEN BREAK
  187.                 END
  188.                 endpos=pos(boundary,out)
  189.                 IF endpos~=0 THEN DO
  190.                     endpos=lastpos(NL,out,endpos)
  191.                     out=LEFT(out,endpos)
  192.                 END
  193.                 IF endpos=0 THEN out=ibserror || out
  194.             END
  195.  
  196.         /* Alters the status of unread-mails to old if selected */    
  197.             IF alt='YES' THEN  ADDRESS 'COMMAND' 'Filenote' file 'O' 
  198.  
  199.             filepos=LASTPOS('/',file)
  200.             file=DELSTR(file,1,filepos)
  201.  
  202.         /* adding Icons */
  203.             if status='N' then icon=fresh
  204.             if status='U' then icon=new
  205.             if status='R' then icon=repl
  206.             if status='O' then icon=old
  207.             if bin>0  then icon=icon || fileinc
  208.             if gem>1 THEN icon=icon || more
  209.  
  210.         /* Find end of text if not MIME multipart */
  211.             IF bonpos=0 THEN DO
  212.                 endpos=pos('UUDECODE',out)
  213.                 IF endpos~=0 THEN DO
  214.                     endpos=pos(NLNL,out,endpos) 
  215.                     out=LEFT(out,endpos)
  216.                     icon=icon || more
  217.                 END
  218.             END
  219.             
  220.             IF content=1 THEN DO
  221.             /* fixing some swedish characters */
  222.                 CALL MIME "=F6","246" ;    CALL MIME "=E5","229" ;    CALL MIME "=E4","228"
  223.                 CALL MIME "=D6","214" ;     CALL MIME "=C5","197" ;    CALL MIME "=C4","196"
  224.             /* removing some crap */
  225.                 CALL MIME '=20'||NL,"10"; CALL MIME "="||NL,""
  226.                 IF html~=0 THEN out=epre||out
  227.             END
  228.  
  229.             linkpage=linkpage||'<A HREF="file://localhost/'||temppath||'/'||file||'.html">'||titel||'</A>'||icon||NL
  230.             out=pre||titel||icon||NL||'Mail to: '||mailto||out
  231.             IF html=0 THEN out =body||out||epre
  232.             out='<HEAD><TITLE>'||name||'</TITLE></HEAD>'||out
  233.             /* save mailfile */
  234.             open('outputfile',temppath'/'file'.html','W')
  235.                 line=writeln('outputfile',out)
  236.             close('outputfile')
  237.         
  238.             IF mode='DEBUG' THEN say 'processed file 'file' OK!'
  239.         END    
  240.     END
  241.  
  242.     IF alt='YES' THEN ADDRESS 'YAM' 'MAILUPDATE'
  243.  
  244.     /* Save indexfile */
  245.     linkpage=linkpage||'</PRE>'
  246.     open('outputfile',temppath'/newmail.html','W')
  247.     line=writeln('outputfile',linkpage)
  248.     close('outputfile')
  249.  
  250.     ADDRESS 'IBROWSE'
  251.     GOTOURL URL 'file://localhost/'temppath'/newmail.html'
  252.     SCREENTOFRONT
  253. END
  254.  
  255. EXIT
  256.  
  257. MIME:
  258. arg mime,char
  259. len=LENGTH(mime)
  260.     DO WHILE pos(mime,out)~=0 
  261.         mimechar=pos(mime,out)
  262.         out=DELSTR(out,mimechar,len)
  263.         IF char~="" THEN out=INSERT(D2C(char),out,mimechar-1)
  264.     END
  265. RETURN
  266.  
  267. START:
  268. arg program,option
  269.     ADDRESS 'COMMAND'
  270.     'RUN >NIL: 'program':'program' 'option
  271.     'sys:rexxc/waitforport' program
  272. RETURN
  273.  
  274. QUOTECUT:
  275. IF pos('quoted-printable',nextline)~=0 THEN content=1
  276. out=DELSTR(out,1,posb)
  277. posb=0
  278. RETURN
  279.  
  280. SHOWYAM:
  281.     ADDRESS 'YAM' 'INFO VERSION'
  282.     yver=WORD(RESULT,3)
  283.     IF yver>=2 THEN ADDRESS 'COMMAND' 'YAM:YAM'
  284.     ADDRESS 'YAM' 'SHOW'
  285. RETURN
  286.